version 12.1
set more off
capture log close

log using rohlfing_pp_2013.log, replace

use rohlfing_pp_2013, clear

* White's M-test for serial autocorrelation
regress lrfksha mrchp lrfkshal medfksha, cluster(party)
predict resid if e(sample), resid
sort country party year
by country party: gen resid_l = resid[_n-1]
regress resid resid_l mrchp lrfkshal medfksha
display as text "Null of no serial autocorrelation rejected at .10"
drop resid resid_l

*** Generating table 2, page ???
* Test for unobserved heterogeneity by countries
areg lrfksha mrchp lrfkshal medfksha if inf != 1, absorb(pid) /* Null of no heterogeneity rejected */
regress lrfksha mrchp lrfkshal medfksha, cluster(pid)
eststo 

* Using standardized membership change
regress lrfksha mstrchp lrfkshal medfksha, cluster(pid)
eststo 

* Using Eurobarometer public opinion data
regress lrfksha mrchp lrfkshal meanebsha, cluster(pid)
eststo 

* Adding vote share variable
regress lrfksha mrchp lrfkshal medfksha vshl, cluster(pid)
eststo 

* Using natural log of original dependent variable as outcome
regress lnlrfksha mrchp lrfkshal medfksha if inf != 1, cluster(pid)
eststo 

esttab using rohlfing_pp_2013_table2.tab, se ar2 nodep ti("Rohlfing, PP 2013, table 2") ///
	mti("Basic" "Member stand." "EB data" "Vote share" "Nat. log.") ///
	r ty b(3) se(4) order(mrchp mstrchp lrfkshal medfksha meanebsha vshl _cons) ///
	star (* .10 ** .05 *** .01)
eststo clear


* Government membership effect
use rohlfing_pp_2013_opp, clear

reg lrfksha mrchp opp i_opp lrfkshal medfksha, cluster(pid)
/* effect for government parties not significant */
eststo


* Extracting relevant information for calculation of marg. eff and stand. err.
matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)
display conb conse conb/conse
drop conb conse
/* effect for opposition parties is significant */

esttab using rohlfing_pp_2013_opp.tab, se ar2 nodep ti("Opposition hypothesis") ///
	mti("Opposition") ///
	r ty b(4) se(3) order(mrchp opp i_opp lrfkshal medfksha _cons) ///
	star (* .10 ** .05 *** .01)
eststo clear
clear


**************************************
* Moderating effect of party finance *
**************************************

use rohlfing_pp_2013, clear
* Party finance in place
regress lrfksha mrchp partyfin i_partyfin lrfkshal medfksha, cluster(pid)
eststo 

* Extracting relevant information for calculation of marg. eff and stand. err.
matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)
display conb conse conb/conse
drop conb conse


*******************************************
* Moderating effect of niche party status *
*******************************************

regress lrfksha mrchp niche i_niche lrfkshal medfksha, cluster(pid)
eststo

matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)
display conb conse conb/conse
drop conb conse


* Combined model: niche and public finance
regress lrfksha mrchp niche i_niche partyfin i_partyfin lrfkshal medfksha, cluster(pid)
eststo

* Marginal effect for niche parties
matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)

display conb conse
drop conb conse

* Marginal effect for opposition parties
scalar b1=b[1,1]
scalar b5=b[1,5]

scalar varb1=V[1,1]
scalar varb5=V[5,5]

scalar covb1b5=V[1,5]

gen conb =b1+b5
gen conse = sqrt(varb1+varb5+2*covb1b5)

display conb conse
display "t-value of marginal effect of membership change when state finance is granted is " conb/conse
drop conb conse

esttab using rohlfing_pp_2013_table3.tab, se ar2 nodep ///
	ti("Hypotheses on mechanisms") mti("State finance" "Niche parties" "Combined") ///
	r ty b(3) se(4) order(mrchp partyfin i_partyfin niche i_niche lrfkshal medfksha _cons) ///
	star (* .10 ** .05 *** .01)
eststo clear


********************************
* Disaggregating niche parties *
********************************

* Dummy for ecological parties
gen ecology = cond(parfam == 10, 1, 0)
label var ecology "Green party"
gen i_ecol = ecol*mrchp

* Dummy for communist parties
gen communist = cond(parfam == 20, 1, 0)
label var communist "Communist party"
gen i_comm = comm*mrchp

/* no data for nationalist parties available */

replace ecology = . if communist == 1 | nationalist == 1
replace communist = . if ecology == 1 | nationalist == 1


areg lrfksha mrchp lrfkshal medfksha ecology i_ecol if inf != 1, absorb(cid) /* significant */
areg lrfksha mrchp lrfkshal medfksha ecology i_ecol if inf != 1, absorb(eid) /* not significant */
areg lrfksha mrchp lrfkshal medfksha ecology i_ecol if inf != 1, absorb(pid) /* significant */

* Ecological parties
areg lrfksha mrchp ecology i_ecol lrfkshal medfksha if inf != 1, cluster(pid) absorb(cid) /* significant */
* Extracting relevant information for calculation of marg. eff and stand. err.
matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)
display e(r2_a) conb conse conb/conse
drop conb conse
* effect negative and significant at .10

*** Communist parties
areg lrfksha mrchp lrfkshal medfksha communist i_comm if inf != 1, absorb(cid) /* significant */
areg lrfksha mrchp lrfkshal medfksha communist i_comm if inf != 1, absorb(eid) /* not significant */
areg lrfksha mrchp lrfkshal medfksha communist i_comm if inf != 1, absorb(pid) /* significant */


areg lrfksha mrchp lrfkshal medfksha communist i_comm if inf != 1, cluster(pid) absorb(cid)
* Extracting relevant information for calculation of marg. eff and stand. err.
matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)
display e(r2_a) conb conse conb/conse
drop conb conse
* effect positive and significant at .10


*****************************************
* Using alternative membership variable *
*****************************************

sort country party year
by country party: gen memstp_ch = memstp-memstp[_n-1]
label var memstp_ch "Difference stand. membership t to t-1"
replace memstp_ch = round(memstp_ch, .01)

regress lrfksha mrchp lrfkshal medfksha, cluster(pid)

regress lrfksha memstp_ch lrfkshal medfksha, cluster(pid)


******************************
* Test with expanded dataset *
******************************

use rohlfing_pp_2013_expanded, clear
/* Data additionally including observations from 
	Mair, Peter and Ingrid van Biezen (2001): Party Membership in 
	Twenty European Democracies, 1980-2000. Party Politics 7 (1): 5-21. */

	
* Analysis
regress lrfksha mrchp lrfkshal medfksha if year < 1993, cluster(party)
/* original analysis */
eststo 

regress lrfksha mrchp lrfkshal medfksha, cluster(party)
/* full expanded data */
eststo

regress lrfksha mrchp nineties i_nine lrfkshal medfksha, cluster(party)
eststo
* Extracting relevant information for calculation of marg. eff and stand. err. of parties in late 1999s
matrix b=e(b)
matrix V=e(V)

scalar b1=b[1,1]
scalar b3=b[1,3]

scalar varb1=V[1,1]
scalar varb3=V[3,3]

scalar covb1b3=V[1,3]

gen conb =b1+b3
gen conse = sqrt(varb1+varb3+2*covb1b3)
display conb conse conb/conse
drop conb conse
* effect not significant for parties in 1990s 

esttab using rohlfing_pp_2013_nineties.tab, se ar2 nodep ///
	ti("Hypotheses on mechanisms") mti("Basic model" "Pooled model" "Interaction") ///
	r ty b(4) se(4) order(mrchp nineties i_nine medfksha _cons) ///
	star (* .10 ** .05 *** .01)
eststo clear


*** Testing for influential observations by case-wise deletion
use rohlfing_pp_2013_robust, clear
log using rohlfing_pp_2013_full.log, replace
sort country party year
gen casewise = _n
gen mrchp_b = .
gen mrchp_se = .
gen mrchp_t = .
sum lrfkshal
local N = r(N)
forvalues n = 1/`N' {
	quietly: regress lrfksha mrchp lrfkshal medfksha if casewise != `n', cluster(party)
	quietly: replace mrchp_b = _b[mrchp] in `n'
	quietly: replace mrchp_se = _se[mrchp] in `n'
	quietly: replace mrchp_t = mrchp_b/mrchp_se in `n'
}

scatter mrchp_b mrchp_t, ///
	xline(1.96) ///
	xtitle("t-value (red line at 1.96)") ytitle("Marginal effect of membership change")

drop casewise mrchp_b mrchp_se mrchp_t

* Running a robust regression
regress lrfksha mrchp lrfkshal medfksha, cluster(party)
rreg lrfksha mrchp lrfkshal medfksha
clear


*************************************************************
* Testing for robustness of alternative estimation strategy *
*************************************************************

use rohlfing_pp_2013, clear
* Baseline model
regress lrfksha mrchp lrfkshal medfksha, cluster(party)
eststo

* Feasible generalized least squares 
xtset pid timevar
xtgls lrfksha mrchp lrfkshal medfksha /* cluster option not allowed*/
eststo

* PCSE 
sort country party year
by country party: gen elec_num = _n	/* generating time variable for xtpcse command */

xtset elec_num pid
xtpcse lrfksha mrchp lrfkshal medfksha, correlation(ar1) pairwise
eststo 

esttab using rohlfing_pp_2013_panel.tab, se r2 nodep ///
	ti("Robustness to control for panel heteroskedasticity") mti("Baseline" "FGLS" "PCSE") ///
	r ty b(3) se(4) order(mrchp lrfkshal medfksha _cons) ///
	star (* .10 ** .05 *** .01)
eststo clear
drop elec_num


										****************************************
										* Analyses only in supplementary paper *
										****************************************

****************************************
* Testing for country-specific effects *
****************************************

* Baseline model
regress lrfksha mrchp lrfkshal medfksha, cluster(pid)
eststo

* Standard errors clustered by countries instead of parties
regress lrfksha mrchp lrfkshal medfksha, cluster(cid)
eststo 

* Baseline model plus country dummies
regress lrfksha mrchp lrfkshal medfksha ///
	c1 c2 c3 c4 c6 c9 c10 c12 c13 c16, cluster(pid)
eststo

esttab using rohlfing_pp_2013_country.tab, se ar2 nodep ///
	ti("Control for unobserved country heterogeneity") mti("Basic model" "Clustered by country" "Country dummies") ///
	r ty b(3) se(4) order(mrchp lrfkshal medfksha _cons) ///
	star (* .10 ** .05 *** .01)
eststo clear


*********************************
* Using traditional CMP measure *
*********************************

* Specification tests with basic model with CMP data
regress lrsha mrchp lrshal medsha, cluster(pid)
predict resid, resid
sort country party year
by country party: gen resid_l = resid[_n-1]
regress resid resid_l mrchp lrshal medsha
display as text "Null of no autocorrelation not rejected"

areg lrsha mrchp lrshal medsha, absorb(cid)
display as text "Null of country-specific effects rejected"

areg lrsha mrchp lrshal medsha, absorb(pid)
display as text "Null of party-specific effects rejected"

areg lrsha mrchp lrshal medsha, absorb(eid)
display as text "Null of electiob-specific effects rejected"

* Basic model with country dummies
areg lrsha mrchp lrshal medsha, cluster(pid) absorb(cid)
eststo 

* Using standardized membership change
areg lrsha mstrchp lrshal medsha, cluster(pid) absorb(cid)
eststo 

* Using Eurobarometer public opinion data
areg lrsha mrchp lrshal meanebsha, cluster(pid) absorb(cid)
eststo 

* Adding vote share variable
areg lrsha mrchp lrshal medsha vshal, cluster(pid) absorb(cid)
eststo 

* Using natural log of original dependent variable as outcome
areg lnlrsha mrchp lrshal medsha, cluster(pid) absorb(cid)
eststo 

esttab using rohlfing_pp_2013.tab, se ar2 nodep ti("Replication with CMP data") ///
	mti("Basic" "Member stand." "EB data" "Vote share" "Nat. log." ) ///
	r ty b(3) se(4) order(mrchp mstrchp lrshal medsha meanebsha _cons) ///
	star (* .10 ** .05 *** .01)	/* table 2 in supplementary paper */
eststo clear

* Test for convergent validity of Franzmann-Kaiser data and CMP data
quietly: regress lrfksha mrchp lrfkshal medfksha, cluster(party)
pwcorr lrcmp lrfk if e(sample), sig obs	/* table 3 in supplementary paper */

log close
